package src.main.lagou.pt.week2homework;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class AClass {

    public static void main(String[] args) throws IOException {

        Socket s = null;
        FileInputStream in = null;
        BufferedOutputStream out = null;

        try {
            // 1.创建Socket类型的对象并提供服务器的主机名和端口号
            s = new Socket("localhost", 8885);

            File file = new File ("/Users/mac/Desktop/BigDataLearnGround/workspace/idea/springboot-redis/src/main/lagou/pt/week2homework/MySort.class");
            in = new FileInputStream(file);

            byte[] buf = new byte[1024];
            int lenght = 0;
            out = new BufferedOutputStream(s.getOutputStream());

            while((lenght = in.read(buf))!=-1){
                out.write(buf,0, lenght);
            }

        } catch (IOException /*| InterruptedException*/ e) {
            e.printStackTrace();
        } finally {
            // 3.关闭Socket并释放有关的资源
            if (null != in) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (null != out) {
                out.close();
            }
            if (null != s) {
                try {
                    s.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
